home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Games / Starter / JST / Developer / sources / src / loaders / Menace / decode.asm < prev    next >
Encoding:
Assembly Source File  |  1999-12-03  |  2.6 KB  |  166 lines

  1.     XDEF    _DecodeTrack
  2.     XDEF    DecodeTrack
  3.  
  4. SYNC_WORD =$4489
  5.  
  6. GETLONG:MACRO
  7.     movem.l    D3-D4,-(sp)
  8.     move.l    (A1)+,\1    ; higher part (dest register)
  9.     move.l    (A1),D3
  10.     lsr.l    D0,D3        ; shift lower part with count
  11.     moveq    #$20,D4
  12.     sub.l    D0,D4
  13.     lsl.l    D4,\1        ;higher part has to be shifted to fill
  14.     or.l    D3,\1        ;the rest-place, a longword has 20 bits
  15.     movem.l    (sp)+,D3-D4    
  16.     ENDM
  17.  
  18. start:
  19.     move.l    #dectrack,A0
  20.     move.l    #rawtrack,D0
  21.     bsr    DecodeTrack
  22.     rts
  23.  
  24. ResyncTrack:
  25.     move.l    RawBuffer(pc),A0
  26.     move.l    Shift(pc),D0
  27.     move.l    #$1850,D1
  28.     subq.l    #6,A0
  29.     lea    synctrack,A1
  30. st_loop:
  31.     move.l    (A0),D2
  32.     lsr.l    D0,D2
  33.     addq.l    #2,A0
  34.     move.w    D2,(A1)+
  35.     dbf    D1,st_loop
  36.     rts
  37.  
  38. ; ** C entrypoint
  39.  
  40. _DecodeTrack:
  41.     move.l    4(A7),D0    ; raw buffer
  42.     move.l    8(A7),A0    ; destination (decoded)
  43.  
  44. ; ** assembly entrypoint
  45.  
  46. DecodeTrack:
  47.     movem.l    D1-A6,-(sp)
  48.  
  49.     move.l    A0,A1    ; dec
  50.     move.l    D0,A0    ; raw
  51.  
  52.     bsr    GetSync
  53.     tst.l    D0
  54.     bne    syncerr
  55.  
  56.     move.l    A1,DecodedBuffer
  57.     move.l    A0,RawBuffer
  58.     move.l    D1,Shift
  59.  
  60.     bsr    ResyncTrack
  61.  
  62.     lea    synctrack,A1
  63.     addq.l    #8,A1
  64.     move.l    DecodedBuffer,A0
  65.  
  66.     bsr    Decode
  67.  
  68.     ; checksum
  69.  
  70.     moveq    #0,D3
  71.     MOVEA.L    A0,A1            ;1F4: 2248
  72.     MOVE    #$0C1B,D4        ;1F6: 383C0C1B
  73. LAB_0006:
  74.     ADD    (A1)+,D3        ;1FA: D659
  75.     DBF    D4,LAB_0006        ;1FC: 51CCFFFC
  76.     MOVE    (A1),D4            ;200: 3811
  77.     CMP    D3,D4            ;202: B843
  78.     bne    decodeerr
  79.  
  80.     moveq    #0,D0
  81. exit
  82.     movem.l    (sp)+,D1-A6
  83.     rts
  84.  
  85.  
  86. decodeerr
  87.     moveq    #1,D0
  88.     bra    exit
  89.  
  90. syncerr
  91.     moveq    #2,D0
  92.     bra    exit
  93.  
  94. Decode:
  95.     MOVEM.L    D0-D1/A0,-(A7)        ;1E2: 48E7C080
  96.     MOVE    #$0C1C,D7        ;220: 3E3C0C1C
  97. LAB_0008:
  98.     MOVE    (A1)+,D0        ;224: 3019
  99.     MOVE    (A1)+,D1        ;226: 3219
  100.     ASL    #1,D0            ;228: E340
  101.     ANDI    #$AAAA,D0        ;22A: 0240AAAA
  102.     ANDI    #$5555,D1        ;22E: 02415555
  103.     OR    D1,D0            ;232: 8041
  104.     MOVE    D0,(A0)+        ;234: 30C0
  105.     DBF    D7,LAB_0008        ;236: 51CFFFEC
  106.     MOVEM.L    (A7)+,D0-D1/A0        ;1EE: 4CDF0103
  107.     RTS                
  108.  
  109. GetSync:
  110.     movem.l    D2-D6/A1-A6,-(sp)
  111.  
  112.     MOVE.L    A0,A2
  113.     lea    $7C00(A2),A4        ;end of rawtrack
  114.  
  115. .SHF2    MOVEQ.L    #$10-1,D5
  116.  
  117.     ; *** try to find the sync shift (0 to 15)
  118.  
  119. .SHF1    MOVE.L    (A2),D0        ; a longword of data
  120.     LSR.L    D5,D0        ; shift it by D5
  121.     CMP.W    #SYNC_WORD,D0    ; sync?
  122.     BEQ.S    .SY        ; yes: found sync AND shift
  123.     DBF    D5,.SHF1
  124.     ADDQ.L    #2,A2
  125.     cmp.l    A2,A4
  126.     beq    ErrorSyn
  127.     BRA.S    .SHF2
  128.  
  129.     ; ** shift has been found, sync too.
  130.  
  131. .SY    MOVE.L    (A2),D0
  132.     ADDQ.L    #2,A2
  133.     LSR.L    D5,D0            ;d5 is the shifting-number when sync was found
  134.     CMP.W    #SYNC_WORD,D0
  135.     BNE.S    .SY
  136.  
  137. .1    MOVE.L    (A2),D0
  138.     ADDQ.L    #2,A2
  139.     LSR.L    D5,D0
  140.     CMP.W    #SYNC_WORD,D0
  141.     BEQ.S    .1
  142.  
  143.     moveq    #0,D0
  144.     move.l    A2,A0    ; buffer synced
  145.     move.l    D5,D1    ; shift
  146.     bra    ExitSyn
  147.  
  148. ErrorSyn:
  149.     moveq    #-1,D0
  150. ExitSyn
  151.     movem.l    (sp)+,D2-D6/A1-A6
  152.     rts
  153. RawBuffer:
  154.     dc.l    0
  155. DecodedBuffer:
  156.     dc.l    0
  157. Shift:
  158.     dc.l    0
  159. dectrack:
  160. ;    blk.b    $1900,0
  161. rawtrack:
  162. ;    incbin    "menace.raw"
  163.  
  164. synctrack:
  165.     blk.w    $1900,0
  166.